﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Core.Exceptions;
using Enterprise.Framework.DomainModel.Repositories;

namespace Resto.CostControl.Core.Domain.Query.SiteModule
{
    internal class SiteCostDQO : IDomainQueryObject
    {
        public SiteCost GetSiteCost(string id)
        {
            SiteCost cost = GetSiteCostOrDefault(id);

            if (cost == null)
                throw new BusinessException("指定Id的项目点成本记录不存在");

            return cost;
        }

        public SiteCost GetSiteCostOrDefault(string id)
        {
            IEntityRepository<SiteCost> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<SiteCost>();
            SiteCost material = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return material;
        }
    }
}
